package com.headwind.logistics.system.controller;

import com.headwind.logistics.common.util.LayuiUtil;
import com.headwind.logistics.common.util.RestResult;
import com.headwind.logistics.common.util.ResultCode;
import com.headwind.logistics.common.util.ResultGenerator;
import com.headwind.logistics.system.dto.IntegralMallDetailDto;
import com.headwind.logistics.system.pojo.IntegralMall;
import com.headwind.logistics.system.service.intl.IntegralMallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author你爸爸 Date2020/7/27 15:08
 * Version 1.0
 * DESCRIPTION
 */
@Controller
public class IntegralMallController {
    @Autowired
    private IntegralMallService integralMallService;

    @Resource
    private ResultGenerator resultGenerator;
    //查询
    @RequestMapping("/admin/system/selectIntegralMall")
    @ResponseBody
    public LayuiUtil selectIntegralMall(Integer page, Integer limit){
        List<IntegralMall> list=integralMallService.selectIntegralMall(page,limit);
        return LayuiUtil.data(integralMallService.selectIntegralMall(null,null).size(),list);
    }

    //查询兑换记录
    @RequestMapping("/admin/system/selectIntegralMallDetail")
    @ResponseBody
    public LayuiUtil selectIntegralMallDetail(Integer page, Integer limit,Integer integralMallId){
      List<IntegralMallDetailDto> list=integralMallService.selectIntegralMallDetail(page,limit,integralMallId);
      return LayuiUtil.data(integralMallService.selectIntegralMallDetail(null,null,null).size(),list);
    }

    //新增
    @RequestMapping("/admin/system/insertIntegralMallDetail")
    @ResponseBody
    public RestResult insertIntegralMallDetail(String integralMallName,String integralMallImg,Integer integralPrice,String createTime){
        IntegralMall integralMall=new IntegralMall();
        integralMall.setCreateTime(createTime);
        integralMall.setIntegralMallImg(integralMallImg);
        integralMall.setIntegralMallName(integralMallName);
        integralMall.setIntegralPrice(integralPrice);
        int count=integralMallService.insertIntegralMallDetail(integralMall);
        if (count >0){
            return resultGenerator.getSuccessResult("新增成功",count);
        }
        return resultGenerator.getFailResult("新增失败",count);
    }

    //删除
    @RequestMapping("/admin/system/deleteIntegralMall")
    @ResponseBody
    public RestResult deleteIntegralMall(Long integralMallId){
        int count=integralMallService.deleteIntegralMall(integralMallId);
        if (count>0){
            return  resultGenerator.getSuccessResult("删除成功",count);
        }
        return resultGenerator.getFailResult("删除失败，重新试试？",count);
    }
}
